package refactor.encapsulatecollection.original;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

public class Client {
    public void clientMethod() {
        Person dayna = new Person();
        Set<Course> courses = new HashSet<>();
        courses.add(new Course("Math", true));
        courses.add(new Course("English", false));
        dayna.setCourses(courses);
        assertThat(dayna.getCourses().size()).isEqualTo(2);
        Course chinese = new Course("Chinese", true);
        dayna.getCourses().add(chinese);
        dayna.getCourses().add(new Course("Java", true));
        assertThat(dayna.getCourses().size()).isEqualTo(4);
        dayna.getCourses().remove(chinese);
        assertThat(dayna.getCourses().size()).isEqualTo(3);
        int count = 0;
        Iterator<Course> courseIterator = dayna.getCourses().iterator();
        while (courseIterator.hasNext()) {
            Course course = courseIterator.next();
            if (course.isAdvanced()) {
                count++;
            }
        }
        assertThat(count).isEqualTo(2);
    }

    public static void main(String[] args) {
        new Client().clientMethod();
    }
}
